﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;

namespace Team4Mock.DAO
{
    public class ProgrammeDAO
    {
        readonly Helper _helper = new Helper();
        public DataTable GetData()
        {
            return _helper.GetData("Pro_GetData");
        }
        public DataTable GetTrue()
        {
            return _helper.GetData("Pro_GetdataTrue");
        }
        public DataTable GetById(int programId)
        {
            var p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", programId) { SqlDbType = SqlDbType.Int };
            return _helper.GetData("Pro_GetdataByID", p);
        }
        public DataTable Search(string keyWord)
        {
            var p = new SqlParameter[1];
            p[0] = new SqlParameter("@keyword", keyWord) { SqlDbType = SqlDbType.VarChar };
            return _helper.GetData("Pro_Search", p);
        }
        public DataTable SearchTrue(string keyWord)
        {
            var p = new SqlParameter[1];
            p[0] = new SqlParameter("@keyword", keyWord) { SqlDbType = SqlDbType.VarChar };
            return _helper.GetData("Pro_SearchTrue", p);
        }

        public void InsertData(string programName, string description, int contactId, int isActive)
        {
            var p = new SqlParameter[4];
            p[0] = new SqlParameter("@name", programName) { SqlDbType = SqlDbType.NVarChar };
            p[1] = new SqlParameter("@des", description) { SqlDbType = SqlDbType.NVarChar };
            p[2] = new SqlParameter("@contact", contactId) { SqlDbType = SqlDbType.Int };
            p[3] = new SqlParameter("@active", isActive) { SqlDbType = SqlDbType.Int };
            
               _helper.ExecuteNonQuerry("Pro_Insert",p);
        }
        public void UpdatetData(int id, string programName, string description, int contactId,int active)
        {
            var p = new SqlParameter[5];
            p[0] = new SqlParameter("@id", id) { SqlDbType = SqlDbType.Int };
            p[1] = new SqlParameter("@name", programName) { SqlDbType = SqlDbType.NVarChar };
            p[2] = new SqlParameter("@des", description) { SqlDbType = SqlDbType.NVarChar };
            p[3] = new SqlParameter("@contact", contactId) { SqlDbType = SqlDbType.Int };
            p[4] =new SqlParameter("@active", active) { SqlDbType = SqlDbType.Int };
            _helper.ExecuteNonQuerry("Pro_Update", p);
        }
        public void Del(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            _helper.ExecuteNonQuerry("Pro_Del", p);
        }
    }
}